package com.magic.smartcity.view.more.park

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.magic.smartcity.R
import com.magic.smartcity.databinding.FragmentParkRecordBinding
import com.magic.smartcity.view.more.adapters.ParkRecordListAdapter
import com.magic.smartcity.view.more.viewmodels.ParkViewModel

class ParkRecordFragment : Fragment() {
    private lateinit var binding:FragmentParkRecordBinding
    private val parkRecordAdapter = ParkRecordListAdapter()
    private val viewModel by lazy {
        ViewModelProvider(this).get(ParkViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel.getParkRecordList()
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentParkRecordBinding.inflate(layoutInflater)
        initView()
        return binding.root
    }

    private fun initView() {
        //初始化历史数据
        binding.parkRecordRy.layoutManager = LinearLayoutManager(requireContext(),LinearLayoutManager.VERTICAL,false)
        binding.parkRecordRy.adapter = parkRecordAdapter
        viewModel.parkRecordList.observe(viewLifecycleOwner){
            parkRecordAdapter.setData(it)
        }
    }
}